﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace SPCoder.Windows
{
    public partial class GridViewer : DockContent
    {
        public GridViewer()
        {
            InitializeComponent();
        }

        public object GridSource { get; set; }

        private void btnView_Click(object sender, EventArgs e)
        {
            //grid.DataSource

            try
            {
                SPCoderForm.ironPythonEngine.SetVariable("myGridViewer", this);
                string code = "myGridViewer.GridSource = " + txtCode.Text + "";
                SPCoderForm.ironPythonEngine.Execute(code);
                grid.AutoGenerateColumns = true;

                var source = new BindingSource();                
                source.DataSource = GridSource;
                grid.DataSource = source;

                //grid.DataSource = this.GridSource;
                
            }
            catch (Exception exc)
            {
                //MessageBox.Show(exc.Message);
            } 
        }

        private void grid_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }
    }
}
